package game.players.user.running;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.events.constants.Key;

import game.Goal3;
import game.players.SoccerPlayer;
import game.players.states.WithBall;
import game.players.user.BeatenUserPlayer;
import game.players.user.movements.WithBallStationaryUser;

public abstract class WithBallRunningUserPlayer extends WithBall {
	
	private double acceleration = 0;
	
	private static final double MAX_SPEED         = Goal3.MAX_PLAYER_SPEED;
	private static final double MIN_SPEED         = Goal3.PLAYER_SPEED;
	private static final double MAX_ACCELERATION  = 1;
	private static final double ACCELERATION_RATE = 0.005;

	public WithBallRunningUserPlayer(SoccerPlayer player) {
		super(player);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		
		if (!deltaState.isKeyBeingHold(Key.SHIFT)) {
			this.getPlayer().setMovementSpeed(MIN_SPEED);
			this.getPlayer().setState(new WithBallStationaryUser(this.getPlayer()));
		}
		
		if (this.getPlayer().getMovementSpeed() < MAX_SPEED && this.getAcceleration() < MAX_ACCELERATION) {
			this.setAcceleration(this.getAcceleration() + ACCELERATION_RATE);
			this.getPlayer().setMovementSpeed(this.getPlayer().getMovementSpeed() + this.getAcceleration());
		}
		else
			this.getPlayer().setMovementSpeed(MAX_SPEED);
	}

	@Override
	public void loseTheBall() {
		this.getPlayer().setState(new BeatenUserPlayer(this.getPlayer(), this.isRight()));
	}
	
	
	
	
	

	public double getAcceleration() {
		return acceleration;
	}

	public void setAcceleration(double acceleration) {
		this.acceleration = acceleration;
	}

}
